/**
 * @author Stéphane LaFlèche <stephane.l@vanillaforums.com>
 * @copyright 2009-2019 Vanilla Forums Inc.
 * @license GPL-2.0-only
 */

@mixin generateButtonClass($buttonMap, $zIndex: false) {
    & {
        @include generateStylesFromMap(map-get($buttonMap, "default"));
    }

    &:not([disabled]) {
        &:hover {
            @include generateStylesFromMap(map-get($buttonMap, "hover"));
        }

        &:active {
            @include generateStylesFromMap(map-get($buttonMap, "focus"));
        }
    }
}

@function inputLineHeight($height, $paddingTop, $fullBorderWidth) {
    @return $height - (2 * $paddingTop + $fullBorderWidth);
}

@mixin selectBoxSizing($height, $fontSize, $paddingSide) {
    min-height: $height;
    font-size: $fontSize;
    padding: {
        left: $paddingSide;
        top: 0;
        bottom: 0;
    }
}

@mixin buttonSizing($height, $minWidth, $fontSize, $paddingTop) {
    min-height: $icon-default_size;
    min-width: $minWidth;
    font-size: $fontSize;
    padding: #{$paddingTop - $formElement-borderWidthFull} #{$paddingTop * 2};
    line-height: $icon-default_size;
}

@mixin textInputSizing($height, $fontSize, $paddingTop) {
    font-size: $fontSize;
    color: $formElement-fg;
    width: 100%;
    height: $height;
    padding: $paddingTop #{$paddingTop * 2};
    line-height: inputLineHeight($height, $paddingTop, $formElement-borderWidthFull);
}

@mixin placeholderStyling {
    &::-webkit-input-placeholder {
        /* Chrome/Opera/Safari */
        @content;
    }
    &::-moz-placeholder {
        /* Firefox 19+ */
        @content;
    }
    &:-ms-input-placeholder {
        /* IE 10+ */
        @content;
    }
    &:-moz-placeholder {
        /* Firefox 18- */
        @content;
    }
}

@mixin outlineStyling-noSelectors($color: $global-color_primary, $inset: false) {
    outline: 0;

    @if ($inset) {
        box-shadow: 0 0 2px $color inset;
    } @else {
        box-shadow: 0 0 2px $color;
    }
}

@mixin outlineStyling($color: $global-color_primary) {
    &:focus,
    &:active {
        @include outlineStyling-noSelectors($color);
    }
}

@mixin outlineStylingInset($color: $global-color_primary) {
    &:focus,
    &:active {
        @include outlineStyling-noSelectors($color, true);
    }
}

@mixin removeSpinner {
    -moz-appearance: textfield;

    &::-webkit-outer-spin-button,
    &::-webkit-inner-spin-button {
        -webkit-appearance: none;
    }

    &::-ms-clear {
        display: none;
    }
}

@mixin standardBorderStyles {
    border: {
        radius: $formElement_borderRadius;
        width: $formElement_borderWidth;
        color: $formElement_borderColor;
        style: solid;
    }

    &.isInvalid {
        border: {
            color: $global-error_fg;
        }

        color: $global-error_fg;
        background: $global-error_bg;
    }
}
